#include "GameLocal.h"
#include "GameEditLocal.h"
#include "../infLib/infLib.h"
#include "../sys/Sys_public.h"
#include "../framework/FileSystem.h"
#include "../framework/DeclManager.h"
#include "../framework/Common.h"
#include "../framework/CVarSystem.h"
#include "../framework/CmdSystem.h"
#include "../renderer/RenderSystem.h"
#include "../renderer/RenderWorld.h"
#include "../renderer/RenderModel.h"
#include "GameEntity.h"

#ifdef  GAME_STATIC
infSys*         sys = NULL;
FileSystem*     fileSystem = NULL;
DeclManager*    declManager = NULL;
Common*         common = NULL;
CVarSystem*     cvarSystem = NULL;
CmdSystem*      cmdSystem = NULL;
RenderSystem*   renderSystem = NULL;
#endif

GameLocal gameLocal;
Game*   game = &gameLocal;

static gameExport_t* GetGameAPI_Proc( gameImport_t* gameImport ) {
    static gameExport_t gameExport;

    sys = gameImport->sys;
    fileSystem = gameImport->fileSystem;
    declManager = gameImport->declManager;
    common = gameImport->common;
    cvarSystem = gameImport->cvarSystem;
    cmdSystem = gameImport->cmdSystem;
    renderSystem = gameImport->renderSystem;

    gameExport.game = game;
    gameExport.gameEdit = gameEdit;


    return &gameExport;
}

GetGameAPI_t GetGameAPI = &GetGameAPI_Proc;


GameLocal::GameLocal()
{

}

GameLocal::~GameLocal()
{

}

void GameLocal::Init()
{
    inf::Str    a("341324"), c;
    c = a + 1.0f;

    RenderWorld* world = renderSystem->AllocRenderWorld();
    renderEntity_t entity;
	
    entity.position = inf::Vec3(0.0f, 0.0f, 0.0f);
    //entity.model = world->GenerateStaticModel(GT_TRIANGLE);
    //entity.model = world->GenerateStaticModel(GT_CUBE);
    entity.model = world->ImportModelFromFile("model/cube.ase");
    //entity.model = world->ImportModelFromFile("model/teapot.ase");
    world->AddEntity( entity );
	GameEntity gameEnt(&entity);
	gameEnt.initPhy();

    renderLight_t light;
    light.position = inf::Vec3(1.0f, 15.0f, -5.0f);
    light.lightMaterial = NULL;
    light.radius = 60.0f;
    world->AddLight( light );

    renderView_t view = world->GetDefaultView();
    view.viewOrg.set( 20.0f, 20.0f, 60.0f );
    world->SetRenderView( view );

    renderSystem->SetPrimaryWorld( world );
}

void GameLocal::Shutdown()
{

}

void GameLocal::RunGame()
{

}


